package com.lanou.renrenxin.tools;

import android.graphics.Bitmap;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

/**
 * Created by zouhui on 16/3/8.
 */
public class MemoryCache implements ImageLoader.ImageCache {
    private LruCache<String, Bitmap> cache;

    public MemoryCache() {
        this.cache = new LruCache<String,Bitmap>((int) (Runtime.getRuntime().maxMemory()/4)) {
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return value.getRowBytes()*value.getHeight()/1024;
            }
        };
    }

    @Override
    public Bitmap getBitmap(String url) {
        return cache.get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
        cache.put(url,bitmap);
    }
}
